<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<table border="1">
    <caption>个人信息</caption>
    <tr>
        <td>照片:</td>
        <td id="pic_td"></td>
    </tr>
    <tr>
        <td>姓名:</td>
        <td id="name_td"></td>
    </tr>
    <tr>
        <td>年龄:</td>
        <td id="age_td"></td>
    </tr>
    <tr>
        <td>好友:</td>
        <td id="friends_td"></td>
    </tr>
</table>
<button onclick="load()">加载数据</button>
<script>
    function load() {
        //模拟从服务器请求到的数据
        let p = {
            name: "传奇哥", age: 25, url: "../b.jpg",
            friends: ["王昭君", "孙尚香", "安其拉"]
        };
        let nameTd = document.querySelector("#name_td");
        let ageTd = document.querySelector("#age_td");
        nameTd.innerText = p.name;
        ageTd.innerText = p.age;
        //设置显示图片
        let picTd = document.querySelector("#pic_td");
        let img = document.createElement("img");
        img.src = p.url;
        img.width = 100;
        picTd.append(img);
        //显示好友
        let friendsTd = document.querySelector("#friends_td");
        let ul = document.createElement("ul");
        //遍历好友名字数组
        for (let friend of p.friends) {
            //创建li 并设置显示内容为好友名字
            let li = document.createElement("li");
            li.innerText = friend;
            ul.append(li);//li添加到ul里面
        }
        friendsTd.append(ul);//ul添加到td里面
    }
</script>
</body>
</html>